<?php

namespace app\web\controller;

use redis\Redis;
use think\Controller;
use think\facade\Env;

class Home extends Controller
{
    public function index(){
        //直接跳转授权
        $data = request()->param();
        $id = $data['id'] ?? '';
        $merch_code = $data['merch_code'] ?? '';
        $url = Env::get('WEB_URL','');
        if($id) $url = $url.'#/pages/coupon/coupon?id='.$id;
        if($merch_code){
            if(!Redis::redis()->get('douyin:sale:code:'.$merch_code)){
                exit('二维码已过期，请重新扫码！');
            }
            $url = $url.'#/pages/coupon/coupon?merch_code='.$merch_code;
        }
        $config = get_sysset();
        $auth_url = 'https://open.douyin.com/platform/oauth/connect/?client_key='.$config['basic']['client_key'].'&response_type=code&scope=user_info,video.create,data.external.item&redirect_uri='.$url;
        return redirect($auth_url);
    }
}